#-*-coding:utf-8-*-
import os
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *


class ProjectList(QListWidget):
    project_Signal=pyqtSignal(str)
    def __init__(self):
        self.clicked.connect(self._set_data)

    

    def _set_date(self,index):
        print(index)
        self.project_Signal.emit('1')
#通过手动配置项目路径来获取对应的所有相关文件路径
class CGTWProjectConfig(QWidget):

    def __init__(self):
        super(CGTWProjectConfig, self).__init__()
        self.setWindowTitle('项目路径设置')
        self.main_layout=QHBoxLayout()
        self.left_list=QListWidget()

        self.right_info_layout=QVBoxLayout()
        self.right_info_layout.setSpacing(25)
        self.right_info_layout.setAlignment(Qt.AlignTop)
        self.info_label=QLabel('项目路径:')
        self.path_label=QLabel('xxx')
        self.btn=QPushButton('...')
        self.btn.clicked.connect(self._choose_file)
        self.right_info_layout.addWidget(self.info_label)
        self.right_info_layout.addWidget(self.path_label)
        self.right_info_layout.addWidget(self.btn)
        self.main_layout.addWidget(self.left_list)
        self.main_layout.addLayout(self.right_info_layout)
        self.setLayout(self.main_layout)

    def _choose_file(self):
        """
        选择目录
        :return:
        """
        dir = QFileDialog.getExistingDirectory(self, '选择目录')
        self.path_label.setText(dir)


class MyWidget(QWidget):
    def __init__(self):
        super(MyWidget, self).__init__()

        self.setWindowTitle('关联cgtw数据(MZ)')
        #.popen('{} {}'.format(r'C:\python37\python3.exe ',r'C:\python37\mz\scripts\NN.py'))


        self.projectName = ''
        self.eps = ''
        self.shot = ''
        self.init()

        #self.cf = cf
        #self.cf.read(r'C:\cgteamwork\bin\base\nuke_plugin\project.config')  # 读取本地的项目配置文件

        self.icon_path = os.path.join(os.path.dirname(os.path.dirname(__file__)),'imgs','folder.png')

        # 项目的预设路径
        # self.mp_path=r'D:\ffmpeg-20190303'
        self.mp_path = self.getCGTW_path(self.projectName, self.eps, 'mp', 'mp')
        self.mp_temp_path = self.mp_path

        # self.mm_path=r'D:\DingDing'
        self.mm_path = self.getCGTW_path(self.projectName, self.eps, 'mm', 'mm')
        self.mm_temp_path = self.mm_path  # 该全局变量用来记录每次点击item时获取的路径

        # self.mod_path=r'D:\ch'
        self.mod_path = self.getCGTW_path(self.projectName, self.eps, 'mod', 'mod')
        self.mod_temp_path = self.mod_path

        # self.ani_project_path=r'D:\MZ'
        self.ani_project_path = self.getCGTW_path(self.projectName, self.eps, 'ani', 'ani')
        self.ani_project_temp_path = self.ani_project_path
        # self.ani_render_path=r'D:\qycache'
        self.ani_render_path = self.getCGTW_path(self.projectName, self.eps, 'ani', 'ani')
        self.ani_render_temp_path = self.ani_render_path

        # self.env_project_path=r'D:\MZ'
        self.env_project_path = self.getCGTW_path(self.projectName, self.eps, 'env', 'env_project')
        self.env_project_temp_path = self.env_project_path
        # self.env_render_path=r'D:\MZ'
        self.env_render_path = self.getCGTW_path(self.projectName, self.eps, 'env', 'env_render')
        self.env_render_temp_path = self.env_render_path

        # self.efx_project_path = r'D:\MZ'
        self.efx_project_path = self.getCGTW_path(self.projectName, self.eps, 'efx', 'efx_project')
        self.efx_project_temp_path = self.efx_project_path
        # self.efx_render_path = r'D:\MZ'
        self.efx_render_path = self.getCGTW_path(self.projectName, self.eps, 'efx', 'efx_render')
        self.efx_render_temp_path = self.efx_render_path

        # self.lgt_path = r'D:\MZ'
        self.lgt_path = self.getCGTW_path(self.projectName, self.eps, 'lgt', 'lgt')
        self.lgt_temp_path = self.lgt_path

        # self.mg_path = r'D:\MZ'
        self.mg_path= self.getCGTW_path(self.projectName, self.eps, 'mg', 'mg')
        self.mg_temp_path = self.mg_path

        # self.cmp_path = r'D:\MZ'
        self.cmp_path= self.getCGTW_path(self.projectName, self.eps, 'cmp', 'cmp')
        self.cmp_temp_path = self.cmp_path

        self.table = QTabWidget()
        # table.setWindowTitle('MZ_CGTW_FOR_NUKE')

        self.mp_layout = QVBoxLayout()
        self.mm_layout = QVBoxLayout()
        self.mod_layout = QVBoxLayout()
        self.ani_layout = QVBoxLayout()
        self.env_layout = QVBoxLayout()
        self.efx_layout = QVBoxLayout()
        self.lgt_layout = QVBoxLayout()
        self.mg_layout = QVBoxLayout()
        self.cmp_layout = QVBoxLayout()

        ###############
        #######

        ###########   MP布局
        self.mp_project_layout = QHBoxLayout()

        self.mp_label = QLabel('MP路径:')
        self.mp_back_btn = QPushButton('返回上一级')
        self.mp_dir_btn = QPushButton('打开目录')
        self.mp_btn = QPushButton('载入')
        self.mp_project_layout.addWidget(self.mp_label, 25)
        self.mp_project_layout.addWidget(self.mp_back_btn, 15)
        self.mp_project_layout.addWidget(self.mp_dir_btn, 15)
        self.mp_project_layout.addSpacing(20)
        self.mp_project_layout.addWidget(self.mp_btn, 25)

        self.mp_listwidget = QListWidget()
        self.mp_pre_list = self.getFileList(self.mp_path)

        self.mp_listwidget.setIconSize(QSize(15, 15))  # 先整体设置图标大小
        self.set_Items(self.mp_pre_list, self.mp_temp_path, 'mp')

        # 设置多选
        self.mp_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        # 双击
        self.mp_listwidget.doubleClicked.connect(self.mp_double)

        # 返回上一级
        self.mp_back_btn.clicked.connect(self.mp_back)

        # 打开目录
        self.mp_dir_btn.clicked.connect(lambda: self.openDir(self.mp_temp_path))

        # 跟踪载入按钮
        self.mp_btn.clicked.connect(self.mp_load_btn)

        self.mp_layout.addLayout(self.mp_project_layout)
        self.mp_layout.addWidget(self.mp_listwidget)
        ########################

        ############跟踪布局
        self.mm_project_layout = QHBoxLayout()

        self.mm_label = QLabel('相机文件:')
        self.mm_back_btn = QPushButton('返回上一级')
        self.mm_dir_btn = QPushButton('打开目录')
        self.mm_btn = QPushButton('载入')
        self.mm_project_layout.addWidget(self.mm_label, 25)
        self.mm_project_layout.addWidget(self.mm_back_btn, 15)
        self.mm_project_layout.addWidget(self.mm_dir_btn, 15)
        self.mm_project_layout.addSpacing(20)
        self.mm_project_layout.addWidget(self.mm_btn, 25)

        self.mm_listwidget = QListWidget()

        self.mm_pre_list = self.getFileList(self.mm_path)  # 直接获取跟踪工程路径

        # self.mm_listwidget.addItems(self.mm_pre_list)#不用默认，使用自定义item
        # 设置一些图标用来区分吧
        self.mm_listwidget.setIconSize(QSize(15, 15))  # 先整体设置图标大小
        self.set_Items(self.mm_pre_list, self.mm_temp_path, 'mm')

        # 设置多选
        self.mm_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)

        # 设置函数
        #
        # 双击
        self.mm_listwidget.doubleClicked.connect(self.mm_double)
        # self.mm_listwidget.doubleClicked.connect(lambda :self.double
        # (self.mm_listwidget,self.mm_resetListWidget,self.mm_reset_tempPath))

        # 返回上一级
        self.mm_back_btn.clicked.connect(self.mm_back)
        # self.mm_back_btn.clicked.connect(lambda :self.back(self.mm_listwidget,self))

        # 打开目录
        self.mm_dir_btn.clicked.connect(lambda: self.openDir(self.mm_temp_path))

        # 跟踪载入按钮
        self.mm_btn.clicked.connect(self.mm_load_btn)

        self.mm_layout.addLayout(self.mm_project_layout)
        self.mm_layout.addWidget(self.mm_listwidget)

        ######################

        ###########模型布局
        self.mod_project_layout = QHBoxLayout()

        self.mod_label = QLabel('模型路径:')
        self.mod_back_btn = QPushButton('返回上一级')
        self.mod_dir_btn = QPushButton('打开目录')
        self.mod_btn = QPushButton('载入')
        self.mod_project_layout.addWidget(self.mod_label, 25)
        self.mod_project_layout.addWidget(self.mod_back_btn, 15)
        self.mod_project_layout.addWidget(self.mod_dir_btn, 15)
        self.mod_project_layout.addSpacing(20)
        self.mod_project_layout.addWidget(self.mod_btn, 25)

        self.mod_listwidget = QListWidget()
        self.mod_pre_list = self.getFileList(self.mod_path)
        # self.mod_listwidget.addItems(self.mod_pre_list)
        self.mod_listwidget.setIconSize(QSize(15, 15))  # 先整体设置图标大小
        self.set_Items(self.mod_pre_list, self.mod_temp_path, 'mod')

        # 设置多选
        self.mod_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        # 双击
        self.mod_listwidget.doubleClicked.connect(self.mod_double)

        # 返回上一级
        self.mod_back_btn.clicked.connect(self.mod_back)

        # 打开目录
        self.mod_dir_btn.clicked.connect(lambda: self.openDir(self.mod_temp_path))

        # 跟踪载入按钮
        self.mod_btn.clicked.connect(self.mod_load_btn)

        self.mod_layout.addLayout(self.mod_project_layout)
        self.mod_layout.addWidget(self.mod_listwidget)
        ########################

        ########动画布局
        self.ani_project_layout = QHBoxLayout()  # 工程布局

        self.ani_project_label = QLabel('动画工程文件:')
        self.ani_project_back_btn = QPushButton('返回上一级')
        self.ani_project_dir_btn = QPushButton('打开目录')
        self.ani_project_btn = QPushButton('载入')
        self.ani_project_layout.addWidget(self.ani_project_label, 25)
        self.ani_project_layout.addWidget(self.ani_project_back_btn, 15)
        self.ani_project_layout.addWidget(self.ani_project_dir_btn, 15)
        self.ani_project_layout.addSpacing(20)
        self.ani_project_layout.addWidget(self.ani_project_btn, 25)

        self.ani_project_listwidget = QListWidget()
        self.ani_project_pre_list = self.getFileList(self.ani_project_path)
        self.set_Items(self.ani_project_pre_list, self.ani_project_temp_path, 'ani_project')

        self.ani_render_layout = QHBoxLayout()  # 渲染布局
        self.ani_render_label = QLabel('动画小样文件:')
        self.ani_render_back_btn = QPushButton('返回上一级')
        self.ani_render_dir_btn = QPushButton('打开目录')
        self.ani_render_btn = QPushButton('载入')
        self.ani_render_layout.addWidget(self.ani_render_label, 25)
        self.ani_render_layout.addWidget(self.ani_render_back_btn, 15)
        self.ani_render_layout.addWidget(self.ani_render_dir_btn, 15)
        self.ani_render_layout.addSpacing(20)
        self.ani_render_layout.addWidget(self.ani_render_btn, 25)

        self.ani_render_listwidget = QListWidget()
        self.ani_render_pre_list = self.getFileList(self.ani_render_path)
        self.set_Items(self.ani_render_pre_list, self.ani_render_temp_path, 'ani_render')

        self.ani_layout.addLayout(self.ani_project_layout)
        self.ani_layout.addWidget(self.ani_project_listwidget)
        self.ani_layout.addLayout(self.ani_render_layout)
        self.ani_layout.addWidget(self.ani_render_listwidget)

        # 设置多选
        self.ani_project_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.ani_render_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        # 设置函数
        #
        # 双击
        self.ani_project_listwidget.doubleClicked.connect(self.ani_project_double)
        self.ani_render_listwidget.doubleClicked.connect(self.ani_render_double)

        # 返回上一级
        self.ani_project_back_btn.clicked.connect(self.ani_project_back)
        self.ani_render_back_btn.clicked.connect(self.ani_render_back)

        # 打开目录
        self.ani_project_dir_btn.clicked.connect(lambda: self.openDir(self.ani_project_temp_path))
        self.ani_render_dir_btn.clicked.connect(lambda: self.openDir(self.ani_render_temp_path))

        # ani_project载入按钮
        self.ani_project_btn.clicked.connect(self.ani_project_load_btn)
        self.ani_render_btn.clicked.connect(self.ani_render_load_btn)

        ###################

        ########场景布局
        self.env_project_layout = QHBoxLayout()  # 工程布局

        self.env_project_label = QLabel('场景工程文件:')
        self.env_project_back_btn = QPushButton('返回上一级')
        self.env_project_dir_btn = QPushButton('打开目录')
        self.env_project_btn = QPushButton('载入')
        self.env_project_layout.addWidget(self.env_project_label, 25)
        self.env_project_layout.addWidget(self.env_project_back_btn, 15)
        self.env_project_layout.addWidget(self.env_project_dir_btn, 15)
        self.env_project_layout.addSpacing(20)
        self.env_project_layout.addWidget(self.env_project_btn, 25)

        self.env_project_listwidget = QListWidget()
        self.env_project_pre_list = self.getFileList(self.env_project_path)
        self.set_Items(self.env_project_pre_list, self.env_project_temp_path, 'env_project')

        self.env_render_layout = QHBoxLayout()  # 渲染布局
        self.env_render_label = QLabel('场景小样文件:')
        self.env_render_back_btn = QPushButton('返回上一级')
        self.env_render_dir_btn = QPushButton('打开目录')
        self.env_render_btn = QPushButton('载入')
        self.env_render_layout.addWidget(self.env_render_label, 25)
        self.env_render_layout.addWidget(self.env_render_back_btn, 15)
        self.env_render_layout.addWidget(self.env_render_dir_btn, 15)
        self.env_render_layout.addSpacing(20)
        self.env_render_layout.addWidget(self.env_render_btn, 25)

        self.env_render_listwidget = QListWidget()
        self.env_render_pre_list = self.getFileList(self.env_render_path)
        self.set_Items(self.env_render_pre_list, self.env_render_temp_path, 'env_render')

        self.env_layout.addLayout(self.env_project_layout)
        self.env_layout.addWidget(self.env_project_listwidget)
        self.env_layout.addLayout(self.env_render_layout)
        self.env_layout.addWidget(self.env_render_listwidget)

        # 设置多选
        self.env_project_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.env_render_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        # 设置函数
        #
        # 双击
        self.env_project_listwidget.doubleClicked.connect(self.env_project_double)
        self.env_render_listwidget.doubleClicked.connect(self.env_render_double)

        # 返回上一级
        self.env_project_back_btn.clicked.connect(self.env_project_back)
        self.env_render_back_btn.clicked.connect(self.env_render_back)

        # 打开目录
        self.env_project_dir_btn.clicked.connect(lambda: self.openDir(self.env_project_temp_path))
        self.env_render_dir_btn.clicked.connect(lambda: self.openDir(self.env_render_temp_path))

        # env_project载入按钮
        self.env_project_btn.clicked.connect(self.env_project_load_btn)
        self.env_render_btn.clicked.connect(self.env_render_load_btn)

        ###################

        ########特效布局
        self.efx_project_layout = QHBoxLayout()  # 工程布局

        self.efx_project_label = QLabel('特效工程文件:')
        self.efx_project_back_btn = QPushButton('返回上一级')
        self.efx_project_dir_btn = QPushButton('打开目录')
        self.efx_project_btn = QPushButton('载入')
        self.efx_project_layout.addWidget(self.efx_project_label, 25)
        self.efx_project_layout.addWidget(self.efx_project_back_btn, 15)
        self.efx_project_layout.addWidget(self.efx_project_dir_btn, 15)
        self.efx_project_layout.addSpacing(20)
        self.efx_project_layout.addWidget(self.efx_project_btn, 25)

        self.efx_project_listwidget = QListWidget()
        self.efx_project_pre_list = self.getFileList(self.efx_project_path)
        self.set_Items(self.efx_project_pre_list, self.efx_project_temp_path, 'efx_project')

        self.efx_render_layout = QHBoxLayout()  # 渲染布局
        self.efx_render_label = QLabel('特效渲染文件:')
        self.efx_render_back_btn = QPushButton('返回上一级')
        self.efx_render_dir_btn = QPushButton('打开目录')
        self.efx_render_btn = QPushButton('载入')
        self.efx_render_layout.addWidget(self.efx_render_label, 25)
        self.efx_render_layout.addWidget(self.efx_render_back_btn, 15)
        self.efx_render_layout.addWidget(self.efx_render_dir_btn, 15)
        self.efx_render_layout.addSpacing(20)
        self.efx_render_layout.addWidget(self.efx_render_btn, 25)

        self.efx_render_listwidget = QListWidget()
        self.efx_render_pre_list = self.getFileList(self.efx_render_path)
        self.set_Items(self.efx_render_pre_list, self.efx_render_temp_path, 'efx_render')

        self.efx_layout.addLayout(self.efx_project_layout)
        self.efx_layout.addWidget(self.efx_project_listwidget)
        self.efx_layout.addLayout(self.efx_render_layout)
        self.efx_layout.addWidget(self.efx_render_listwidget)

        # 设置多选
        self.efx_project_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.efx_render_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        # 设置函数
        #
        # 双击
        self.efx_project_listwidget.doubleClicked.connect(self.efx_project_double)
        self.efx_render_listwidget.doubleClicked.connect(self.efx_render_double)

        # 返回上一级
        self.efx_project_back_btn.clicked.connect(self.efx_project_back)
        self.efx_render_back_btn.clicked.connect(self.efx_render_back)

        # 打开目录
        self.efx_project_dir_btn.clicked.connect(lambda: self.openDir(self.efx_project_temp_path))
        self.efx_render_dir_btn.clicked.connect(lambda: self.openDir(self.efx_render_temp_path))

        # env_project载入按钮
        self.efx_project_btn.clicked.connect(self.efx_project_load_btn)
        self.efx_render_btn.clicked.connect(self.efx_render_load_btn)

        ###################

        ############渲染布局
        self.lgt_project_layout = QHBoxLayout()

        self.lgt_label = QLabel('渲染文件:')
        self.lgt_back_btn = QPushButton('返回上一级')
        self.lgt_dir_btn = QPushButton('打开目录')
        self.lgt_btn = QPushButton('载入')
        self.lgt_project_layout.addWidget(self.lgt_label, 25)
        self.lgt_project_layout.addWidget(self.lgt_back_btn, 15)
        self.lgt_project_layout.addWidget(self.lgt_dir_btn, 15)
        self.lgt_project_layout.addSpacing(20)
        self.lgt_project_layout.addWidget(self.lgt_btn, 25)

        self.lgt_listwidget = QListWidget()
        self.lgt_pre_list = self.getFileList(self.lgt_path)
        self.set_Items(self.lgt_pre_list, self.lgt_temp_path, 'lgt')

        self.lgt_layout.addLayout(self.lgt_project_layout)
        self.lgt_layout.addWidget(self.lgt_listwidget)

        # 设置多选
        self.lgt_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        # 双击
        self.lgt_listwidget.doubleClicked.connect(self.lgt_double)

        # 返回上一级
        self.lgt_back_btn.clicked.connect(self.lgt_back)

        # 打开目录
        self.lgt_dir_btn.clicked.connect(lambda: self.openDir(self.lgt_temp_path))

        # 跟踪载入按钮
        self.lgt_btn.clicked.connect(self.lgt_load_btn)

        ######################

        ############包装布局
        self.mg_project_layout = QHBoxLayout()

        self.mg_label = QLabel('包装文件:')
        self.mg_back_btn = QPushButton('返回上一级')
        self.mg_dir_btn = QPushButton('打开目录')
        self.mg_btn = QPushButton('载入')
        self.mg_project_layout.addWidget(self.mg_label, 25)
        self.mg_project_layout.addWidget(self.mg_back_btn, 15)
        self.mg_project_layout.addWidget(self.mg_dir_btn, 15)
        self.mg_project_layout.addSpacing(20)
        self.mg_project_layout.addWidget(self.mg_btn, 25)

        self.mg_listwidget = QListWidget()
        self.mg_pre_list = self.getFileList(self.mg_path)
        self.set_Items(self.mg_pre_list, self.mg_temp_path, 'mg')

        self.mg_layout.addLayout(self.mg_project_layout)
        self.mg_layout.addWidget(self.mg_listwidget)

        # 设置多选
        self.mg_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        # 双击
        self.mg_listwidget.doubleClicked.connect(self.mg_double)

        # 返回上一级
        self.mg_back_btn.clicked.connect(self.mg_back)

        # 打开目录
        self.mg_dir_btn.clicked.connect(lambda: self.openDir(self.mg_temp_path))

        # 跟踪载入按钮
        self.mg_btn.clicked.connect(self.mg_load_btn)

        ############合成布局
        self.cmp_project_layout = QHBoxLayout()

        self.cmp_label = QLabel('包装文件:')
        self.cmp_back_btn = QPushButton('返回上一级')
        self.cmp_dir_btn = QPushButton('打开目录')
        self.cmp_btn = QPushButton('载入')
        self.cmp_project_layout.addWidget(self.cmp_label, 25)
        self.cmp_project_layout.addWidget(self.cmp_back_btn, 15)
        self.cmp_project_layout.addWidget(self.cmp_dir_btn, 15)
        self.cmp_project_layout.addSpacing(20)
        self.cmp_project_layout.addWidget(self.cmp_btn, 25)

        self.cmp_listwidget = QListWidget()
        self.cmp_pre_list = self.getFileList(self.cmp_path)
        self.set_Items(self.cmp_pre_list, self.cmp_temp_path, 'cmp')

        self.cmp_layout.addLayout(self.cmp_project_layout)
        self.cmp_layout.addWidget(self.cmp_listwidget)

        # 设置多选
        self.cmp_listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
        # 双击
        self.cmp_listwidget.doubleClicked.connect(self.cmp_double)

        # 返回上一级
        self.cmp_back_btn.clicked.connect(self.cmp_back)

        # 打开目录
        self.cmp_dir_btn.clicked.connect(lambda: self.openDir(self.cmp_temp_path))

        # 跟踪载入按钮
        self.cmp_btn.clicked.connect(self.cmp_load_btn)

        ######################
        self.mp = QWidget()
        self.mm = QWidget()
        self.mod = QWidget()
        self.ani = QWidget()
        self.env = QWidget()
        self.efx = QWidget()
        self.lgt = QWidget()
        self.mg = QWidget()
        self.cmp = QWidget()

        self.mp.setLayout(self.mp_layout)
        self.mm.setLayout(self.mm_layout)
        self.mod.setLayout(self.mod_layout)
        self.ani.setLayout(self.ani_layout)
        self.env.setLayout(self.env_layout)
        self.efx.setLayout(self.efx_layout)
        self.lgt.setLayout(self.lgt_layout)
        self.mg.setLayout(self.mg_layout)
        self.cmp.setLayout(self.cmp_layout)

        self.table.addTab(self.mp, "美术")
        self.table.addTab(self.mm, "跟踪")
        self.table.addTab(self.mod, "模型")
        self.table.addTab(self.ani, "动画")
        self.table.addTab(self.env, '场景')
        self.table.addTab(self.efx, '特效')
        self.table.addTab(self.lgt, '渲染')
        self.table.addTab(self.mg, '包装')
        self.table.addTab(self.cmp, '合成')

        self.master_layout = QHBoxLayout()

        self.master_layout.addWidget(self.table)

        self.setLayout(self.master_layout)


#init初始配置
    def init(self):
        # root=nuke.Root()
        # comment=root['label'].value()
        # try:
        #     comment_list=comment.split('%')
        #     self.projectName = comment_list[0]
        #     self.eps = comment_list[1]
        #     self.shot = comment_list[2]
        # except:
        #     nuke.message("请从cgtw打开nuke,或者在Root面板下comment中输入命令:项目名称%集数%镜头号  例如:SS2%06%SS2_01_06_010")
        #

        pass


    # 初始化获取路径
    def getFileList(self, file_path):
        nameList = os.listdir(file_path)
        return nameList



    # 获取文件开局各路径
    def getCGTW_path(self, project_name, eps, department,path_type):

        path = self.cf.get(project_name, department)
        project_path = ''
        if path_type == 'mp' or path_type == 'mm' or path_type == 'mg' or path_type == 'cmp' or path_type == 'env_render' or path_type == 'efx_render':
            project_path = path + '/' + eps
        elif path_type == 'mod':
            project_path = path
        elif path_type == 'ani' or path_type == 'lgt':
            project_path = path + '/' + eps + '/' + self.shot
        else:
            project_path = path + '/' + eps + '/Render'

        # if PC:
        #     project_path.replace('/','\\')
        if os.path.exists(project_path):
            return project_path
        else:
            return 'C:'

    # 打开当前目录
    def openDir(self, temp_path):
        '''
        这里默认是用Window系统，如果是mac，那么还没测试
        :param temp_path:
        :return:
        '''
        newPath = temp_path.replace('/', '\\')
        os.popen(r'explorer.exe %s' % newPath)

    # 设置自定义item
    def set_Items(self, itemName_list, temp_path, department):
        '''
        设置item并带图标,注意对于自定义item内容，必须先将temp_path运行在渲染listname之前，这样才能根据temp_path
来设置当前item配置
        :param itemName_list:
        :param temp_path:
        :return:
        '''
        for n in itemName_list:
            i = QListWidgetItem()
            path = temp_path + '/' + n
            if os.path.isdir(path):
                i.setIcon(QIcon(self.icon_path))
                i.setText(n)
                if department == 'mp':
                    self.mp_listwidget.addItem(i)
                elif department == 'mm':
                    self.mm_listwidget.addItem(i)
                elif department == 'mod':
                    self.mod_listwidget.addItem(i)
                elif department == 'ani_project':
                    self.ani_project_listwidget.addItem(i)
                elif department == 'ani_render':
                    self.ani_render_listwidget.addItem(i)
                elif department == 'env_project':
                    self.env_project_listwidget.addItem(i)
                elif department == 'env_render':
                    self.env_render_listwidget.addItem(i)
                elif department == 'efx_project':
                    self.efx_project_listwidget.addItem(i)
                elif department == 'efx_render':
                    self.efx_render_listwidget.addItem(i)
                elif department == 'lgt':
                    self.lgt_listwidget.addItem(i)
                elif department == 'mg':
                    self.mg_listwidget.addItem(i)
                elif department == 'cmp':
                    self.cmp_listwidget.addItem(i)
            else:
                i.setText(n)
                if department == 'mp':
                    self.mp_listwidget.addItem(i)
                elif department == 'mm':
                    self.mm_listwidget.addItem(i)
                elif department == 'mod':
                    self.mod_listwidget.addItem(i)
                elif department == 'ani_project':
                    self.ani_project_listwidget.addItem(i)
                elif department == 'ani_render':
                    self.ani_render_listwidget.addItem(i)
                elif department == 'env_project':
                    self.env_project_listwidget.addItem(i)
                elif department == 'env_render':
                    self.env_render_listwidget.addItem(i)
                elif department == 'efx_project':
                    self.efx_project_listwidget.addItem(i)
                elif department == 'efx_render':
                    self.efx_render_listwidget.addItem(i)
                elif department == 'lgt':
                    self.lgt_listwidget.addItem(i)
                elif department == 'mg':
                    self.mg_listwidget.addItem(i)
                elif department == 'cmp':
                    self.cmp_listwidget.addItem(i)

    # 各部门全局变量的更改函数
    # 妈的，为了贪图一个按钮函数可以通用，其他还传那么多不同函数做为参数，不如一个部门写一套函数

    # 跟踪

    # 通用刷新函数
    def resetListWidget(self, listwidget):

        num = listwidget.count()

        for i in range(num):
            listwidget.takeItem(0)

    ######################美术函数


#通用导入nuke函数
    def load(self,temp_path,nameList):
        for n in nameList:
            path=''
            filePath=temp_path+'/'+n
            if os.path.isdir(filePath):
                path=filePath+'/'
            else:
                path=filePath
            pass
            # r=nuke.createNode('Read')
            # r['file'].fromUserText(path)
            # #r['file'].setValue(path)



    def mp_load_btn(self):
        templist = []
        s = self.mp_listwidget.selectedItems()
        showText = ''

        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.mp_temp_path,templist)
        QMessageBox.information(self.mp_listwidget, "标题", "导入{}".format(showText))


    # 返回上一级
    def mp_back(self):
        upPath = os.path.split(self.mp_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.mp_listwidget)

        self.mp_temp_path = upPath
        self.set_Items(upList, self.mp_temp_path, 'mp')

    # 包装双击函数
    def mp_double(self):

        s = self.mp_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.mp_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.mp_listwidget)  # 先清除
            self.mp_temp_path = dirPath
            self.set_Items(newNameList, self.mp_temp_path, 'mp')

        else:
            self.load(self.mp_temp_path, [text])
            QMessageBox.information(self.lgt_listwidget, "标题", "导入{}".format(text))

        print(dirPath)

    # *************跟踪函数
    #
    ##
    #

    def mm_load_btn(self):
        templist = []
        s = self.mm_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())


        self.load(self.mm_temp_path, templist)
        QMessageBox.information(self.mm_listwidget, "标题", "导入{}".format(showText))

    # 返回上一级
    def mm_back(self):
        upPath = os.path.split(self.mm_temp_path)[0]
        # 直接无限返回算了
        upList = os.listdir(upPath)
        self.resetListWidget(self.mm_listwidget)
        # self.mm_listwidget.addItems(upList)
        self.mm_temp_path = upPath
        self.set_Items(upList, self.mm_temp_path, 'mm')

        # 想组织无限返回上一级貌似这样做没用
        # if upPath!=self.mm_path:
        #     upList=os.listdir(upPath)
        #     self.resetListWidget(self.mm_listwidget)
        #     self.mm_listwidget.addItems(upList)
        #     self.mm_temp_path=upPath
        # else:
        #     pass

    # #暂时用不着了
    # def mm_moreSelected(self,self_list_Widget,selectList):
    #     content = ""
    #     # selectList=[]
    #     tempList=[]
    #     for i in self.mm_listwidget.selectedIndexes():
    #         text = i.data()
    #         content += " " + text
    #         tempList.append(text)
    #     QMessageBox.information(self_list_Widget, "标题", "你选择了{}".format(content))
    #     self.selectList=tempList
    #     #print(self.selectList)

    # 跟踪双击函数
    def mm_double(self):

        s = self.mm_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.mm_temp_path + '/' + text  # 现在关键是如何获取到当前文件夹路径，不能使用self.mm_path,因
        # 为可能还存在下层路径
        # 应该是每次刷新listwidget时就立马对应刷了路径，然后根据选择的索引，对应打开路径的索引

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.mm_listwidget)
            # self.mm_listwidget.addItems(newNameList)
            self.mm_temp_path = dirPath
            self.set_Items(newNameList, self.mm_temp_path, 'mm')



        else:
            self.load(self.mm_temp_path, [text])
            QMessageBox.information(self.mm_listwidget, "标题", "导入{}".format(text))

    ######################模型函数

    def mod_load_btn(self):
        templist = []
        s = self.mod_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.mod_temp_path, templist)
        QMessageBox.information(self.mod_listwidget, "标题", "导入{}".format(showText))

    # 返回上一级
    def mod_back(self):
        upPath = os.path.split(self.mod_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.mod_listwidget)

        self.mod_temp_path = upPath
        self.set_Items(upList, self.mod_temp_path, 'mod')

    # 模型双击函数
    def mod_double(self):

        s = self.mod_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.mod_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.mod_listwidget)  # 先清除
            self.mod_temp_path = dirPath
            self.set_Items(newNameList, self.mod_temp_path, 'mod')

        else:
            self.load(self.mod_temp_path, [text])
            QMessageBox.information(self.mod_listwidget, "标题", "导入{}".format(text))

    ######################动画函数

    def ani_project_load_btn(self):
        templist = []
        s = self.ani_project_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.ani_project_temp_path, templist)
        QMessageBox.information(self.ani_project_listwidget, "标题", "导入{}".format(showText))

    def ani_render_load_btn(self):
        templist = []
        s = self.ani_render_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.ani_render_temp_path, templist)
        QMessageBox.information(self.ani_render_listwidget, "标题", "导入{}".format(showText))

    # 返回上一级
    def ani_project_back(self):
        upPath = os.path.split(self.ani_project_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.ani_project_listwidget)

        self.ani_project_temp_path = upPath
        self.set_Items(upList, self.ani_project_temp_path, 'ani_project')

    def ani_render_back(self):
        upPath = os.path.split(self.ani_render_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.ani_render_listwidget)

        self.ani_render_temp_path = upPath
        self.set_Items(upList, self.ani_render_temp_path, 'ani_render')

    # 模型双击函数
    def ani_project_double(self):

        s = self.ani_project_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.ani_project_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.ani_project_listwidget)  # 先清除
            self.ani_project_temp_path = dirPath
            self.set_Items(newNameList, self.ani_project_temp_path, 'ani_project')

        else:
            self.load(self.ani_project_temp_path, [text])
            QMessageBox.information(self.ani_project_listwidget, "标题", "导入{}".format(text))

    def ani_render_double(self):

        s = self.ani_render_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.ani_render_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.ani_render_listwidget)  # 先清除
            self.ani_render_temp_path = dirPath
            self.set_Items(newNameList, self.ani_render_temp_path, 'ani_render')

        else:
            self.load(self.ani_render_temp_path, [text])
            QMessageBox.information(self.ani_render_listwidget, "标题", "导入{}".format(text))

    ######################场景函数

    def env_project_load_btn(self):
        templist = []
        s = self.env_project_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.env_project_temp_path, templist)
        QMessageBox.information(self.env_project_listwidget, "标题", "导入{}".format(showText))

    def env_render_load_btn(self):
        templist = []
        s = self.env_render_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.env_render_temp_path, templist)
        QMessageBox.information(self.env_render_listwidget, "标题", "导入{}".format(showText))

    # 返回上一级
    def env_project_back(self):
        upPath = os.path.split(self.env_project_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.env_project_listwidget)

        self.env_project_temp_path = upPath
        self.set_Items(upList, self.env_project_temp_path, 'env_project')

    def env_render_back(self):
        upPath = os.path.split(self.env_render_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.env_render_listwidget)

        self.env_render_temp_path = upPath
        self.set_Items(upList, self.env_render_temp_path, 'env_render')

    # 场景双击函数
    def env_project_double(self):

        s = self.env_project_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.env_project_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.env_project_listwidget)  # 先清除
            self.env_project_temp_path = dirPath
            self.set_Items(newNameList, self.env_project_temp_path, 'env_project')

        else:
            self.load(self.env_project_temp_path, [text])
            QMessageBox.information(self.env_project_listwidget, "标题", "导入{}".format(text))

    def env_render_double(self):

        s = self.env_render_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.env_render_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.env_render_listwidget)  # 先清除
            self.env_render_temp_path = dirPath
            self.set_Items(newNameList, self.env_render_temp_path, 'env_render')

        else:
            self.load(self.env_render_temp_path, [text])
            QMessageBox.information(self.env_render_listwidget, "标题", "导入{}".format(text))

    ######################特效函数

    def efx_project_load_btn(self):
        templist = []
        s = self.efx_project_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.efx_project_temp_path, templist)
        QMessageBox.information(self.efx_project_listwidget, "标题", "导入{}".format(showText))

    def efx_render_load_btn(self):
        templist = []
        s = self.efx_render_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.efx_render_temp_path, templist)
        QMessageBox.information(self.efx_render_listwidget, "标题", "导入{}".format(showText))

    # 返回上一级
    def efx_project_back(self):
        upPath = os.path.split(self.efx_project_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.efx_project_listwidget)

        self.efx_project_temp_path = upPath
        self.set_Items(upList, self.efx_project_temp_path, 'efx_project')

    def efx_render_back(self):
        upPath = os.path.split(self.efx_render_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.efx_render_listwidget)

        self.efx_render_temp_path = upPath
        self.set_Items(upList, self.efx_render_temp_path, 'efx_render')

    # 特效双击函数
    def efx_project_double(self):

        s = self.efx_project_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.efx_project_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.efx_project_listwidget)  # 先清除
            self.efx_project_temp_path = dirPath
            self.set_Items(newNameList, self.efx_project_temp_path, 'efx_project')

        else:
            self.load(self.efx_project_temp_path, [text])
            QMessageBox.information(self.efx_project_listwidget, "标题", "导入{}".format(text))

    def efx_render_double(self):

        s = self.efx_render_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.efx_render_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.efx_render_listwidget)  # 先清除
            self.efx_render_temp_path = dirPath
            self.set_Items(newNameList, self.efx_render_temp_path, 'efx_render')

        else:
            self.load(self.efx_render_temp_path, [text])
            QMessageBox.information(self.efx_render_listwidget, "标题", "导入{}".format(text))

    ######################渲染函数

    def lgt_load_btn(self):
        templist = []
        s = self.lgt_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.lgt_temp_path, templist)
        QMessageBox.information(self.lgt_listwidget, "标题", "导入{}".format(showText))

    # 返回上一级
    def lgt_back(self):
        upPath = os.path.split(self.lgt_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.lgt_listwidget)

        self.lgt_temp_path = upPath
        self.set_Items(upList, self.lgt_temp_path, 'lgt')

    # 渲染双击函数
    def lgt_double(self):

        s = self.lgt_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.lgt_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.lgt_listwidget)  # 先清除
            self.lgt_temp_path = dirPath
            self.set_Items(newNameList, self.lgt_temp_path, 'lgt')

        else:
            self.load(self.lgt_temp_path, [text])
            QMessageBox.information(self.lgt_listwidget, "标题", "导入{}".format(text))

    ######################包装函数

    def mg_load_btn(self):
        templist = []
        s = self.mg_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.lgt_temp_path, templist)
        QMessageBox.information(self.mg_listwidget, "标题", "导入{}".format(showText))

    # 返回上一级
    def mg_back(self):
        upPath = os.path.split(self.mg_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.mg_listwidget)

        self.mg_temp_path = upPath
        self.set_Items(upList, self.mg_temp_path, 'mg')

    # 包装双击函数
    def mg_double(self):

        s = self.mg_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.mg_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.mg_listwidget)  # 先清除
            self.mg_temp_path = dirPath
            self.set_Items(newNameList, self.mg_temp_path, 'mg')

        else:
            self.load(self.lgt_temp_path, [text])
            QMessageBox.information(self.mg_listwidget, "标题", "导入{}".format(text))

    ######################合成函数

    def cmp_load_btn(self):
        templist = []
        s = self.cmp_listwidget.selectedItems()
        showText = ''
        for n in s:
            showText += ' ' + n.text()
            templist.append(n.text())
        self.load(self.cmp_temp_path, templist)
        QMessageBox.information(self.cmp_listwidget, "标题", "导入{}".format(showText))

    # 返回上一级
    def cmp_back(self):
        upPath = os.path.split(self.cmp_temp_path)[0]
        upList = os.listdir(upPath)
        self.resetListWidget(self.cmp_listwidget)

        self.cmp_temp_path = upPath
        self.set_Items(upList, self.cmp_temp_path, 'cmp')

    # 合成双击函数
    def cmp_double(self):

        s = self.cmp_listwidget.selectedItems()
        text = s[0].text()  # 获取当前双击的item值

        dirPath = self.cmp_temp_path + '/' + text

        if os.path.isdir(dirPath):  # 如果当前选择的是文件夹，我们重新对listWidget刷新内容
            newNameList = os.listdir(dirPath)

            self.resetListWidget(self.cmp_listwidget)  # 先清除
            self.cmp_temp_path = dirPath
            self.set_Items(newNameList, self.cmp_temp_path, 'cmp')

        else:
            self.load(self.cmp_temp_path, [text])
            QMessageBox.information(self.cmp_listwidget, "标题", "导入{}".format(text))

    # def mz_load(self):
    # # os.popen('{} {}'.format(r'C:\python37\python3.exe ',r'C:\cgteamwork\bin\base\nuke_plugin\NN.py'))
    #     pane = nuke.getPaneFor('Properties.1')
    #     panels.registerWidgetAsPanel('MyWidget', 'MZ_Tool', 'uk.co.thefoundry.MyWidget', True).addToPane(pane)

if __name__ == '__main__':
    app=QApplication(sys.argv)
    # m=MyWidget()
    m=CGTWProjectConfig()
    # m=ProjectList()
    m.show()
    sys.exit(app.exec_())